import 'package:tender_flutter/page/common/model/badge_entity.dart';
import 'package:tender_flutter/page/index_page.dart';
import 'package:tender_flutter/page/subscription/api/api_subscription.dart';

/// 红点管理
class BadgeManager {
  factory BadgeManager() => _getInstance();

  static BadgeManager get instance => _getInstance();

  static BadgeManager _instance;

  BadgeManager._internal() {
    // 初始化
  }

  static BadgeManager _getInstance() {
    if (_instance == null) {
      _instance = new BadgeManager._internal();
    }
    return _instance;
  }

  /// 获取订阅的更新数量
  Future updateSubscriptionNum() async {
    var response = await ApiSubscription.subscriptionBadgeNum<BadgeEntity>();
    BadgeEntity entity = response.result;
    if (entity != null) {
      badgeNumNotifier.value = int.parse(entity.num) ?? 0;
    }
  }
}
